package com.naizhuai.ui.rank.multType;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.github.mikephil.charting.charts.LineChart;
import com.naizhuai.R;
import com.naizhuai.util.MPChartHelper;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.drakeet.multitype.ItemViewBinder;

/**
 * @author：lichenxi
 * @date 2018/5/17 12
 * email：525603977@qq.com
 * Fighting
 */
public class OrganizeChartViewBinder extends ItemViewBinder<OrganizeChart, OrganizeChartViewBinder.ViewHolder> {




    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_data_chart, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull OrganizeChart organizeChart) {
        Context context=holder.itemView.getContext();
        holder.initCharView();
        holder.title.setText(organizeChart.name);
        holder.titleCount.setText(context.getString(R.string.space_count,organizeChart.count));
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.linechart)
        LineChart lineChart;
        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.title_count)
        TextView titleCount;
        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        private void initCharView() {
            ArrayList<String> xValues = new ArrayList<>();
            ArrayList<Float> yValues = new ArrayList<>();
            xValues.add("05-06");
            xValues.add("05-07");
            xValues.add("05-08");
            xValues.add("05-09");
            xValues.add("05-10");
            for (int i = 0; i < 5; i++) {
                yValues.add(Float.parseFloat("" + i + 8));
            }
            MPChartHelper.setLineChart(lineChart, xValues, yValues, "", false);
        }
    }
}
